<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2021/3/22
 * Time: 14:17
 */

namespace api\modules\v2\controllers;

use Yii;
use api\controllers\OnAuthController;
use common\models\Bookscate\Bookscate;

class BookscateController extends OnAuthController
{
    public $modelClass =Bookscate ::class;

    protected $authOptional = ['index','two','three','pid'];

    /**
     * @return string|\yii\data\ActiveDataProvider
     */
    public function actionIndex()
    {
        $books = Bookscate::find()->where(['pid'=>0])->all();
        if($books){
            return $books;
        }else{
            return "请求失败";
        }
    }
    public function actionTwo()
    {
        $books = Bookscate::find()->where(['level'=>2])->all();
        if($books){
            return $books;
        }else{
            return "请求失败";
        }
    }
    public function actionPid()
    {
        $pid = Yii::$app->request->get('pid');
        $membercate = Bookscate::find()->where(['pid'=>$pid])->all();
        if(empty($membercate)){
            return "请传入pid";
        }else{
            if ($membercate){
                return $membercate;
            }else{
                return "请求失败";
            }
        }
    }

    public function actionThree()
    {
        $books = Bookscate::find()->where(['level'=>3])->all();
        if($books){
            return $books;
        }else{
            return "请求失败";
        }
    }
}